/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#pragma once

/*-----------------------------------------------------------------------------
	Scene entity stuff :
-----------------------------------------------------------------------------*/

class ERScene;

struct ERShadingGroup {
		uint		start;
		uint		num;
		IPxTexture	texture;
		IPxRSShader	shader;
	};
	

class ERSEntity : public IRSEntity {
	public:
							ERSEntity		( ERScene *scene, IPxTriMesh mesh, const EVec4 &pos, const EQuat &orient );
							~ERSEntity		( void );
						
		virtual void		SetPose			( const EVec4 &position, const EQuat &orient );
		virtual void		GetPose			( EVec4 &position, EQuat &orient ) const;
		virtual void		SetVelocity		( const EVec4 &linear_velocity ) { velocity = linear_velocity; }
		virtual void		GetVelocity		( EVec4 &linear_velocity ) const { linear_velocity = velocity; }

		virtual void		UpdateEntity	( const ERendEntityDesc_s *entity_desc );
		virtual void		Animate			( float time );
		virtual void		Animate			( const IPxTriMeshFrame frame );
		virtual IPxTriMesh	GetTriMesh		( void ) { return origin_mesh; }

		//	local public stuff :
		const ERendEntityDesc_s	*GetEntityDesc	( void ) const;
		const IPxVertexBuffer	GetVertexBuffer	( void ) const;
		void					Render			( void );
		bool					Deleted			( void ) const { return deleted; }
		void					MarkDeleted		( void ) { deleted = true; }
		virtual void			AddDecal		( EVec3 position, EVec3 direction, float radius, EString material );
	protected:
		bool		deleted;
		
		vector<ERShadingGroup>	sgs;
		
		EVec4		position;
		EQuat		orient;
		EVec4		velocity;
	
		ERScene		*scene;
		IPxVertexBuffer	mesh;
		IPxTriMesh  work_mesh;
		IPxTriMesh	origin_mesh;
	};
